package com.gp.controller;

import com.alibaba.fastjson.JSON;
import com.gp.pojo.Goods;
import com.gp.service.GoodsService;
import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/es")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @GetMapping("/add")
    public String add() throws IOException {
        return goodsService.bulkAdd();
    }

    @GetMapping("/findAll")
    public List<Goods> findAll() throws IOException {
        return goodsService.findAll();
    }
}
